//
//  HWpinglunweixingView.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/11/30.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWpinglunweixingView.h"
#import "HWyouxixiqiangpinglunTableViewCell.h"

@interface HWpinglunweixingView()<UITableViewDataSource,UITableViewDelegate>

@end



@implementation HWpinglunweixingView





-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight+57*2) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
       // _mainaTableVie.backgroundColor = RGB(241, 242, 244);
        
    }
    return   _mainaTableVie ;

}


- (instancetype)initWithFrame:(CGRect)frame  {
    
    
    if (self = [super initWithFrame:frame]) {
        
        
        [self setupUI];
        

        
    }
    
    return  self;
    
}


- (void)shuaxingshuju {
    
    
    [self.mainaTableVie reloadData];
    
    
}





- (void)setupUI {
    
    
    [self addSubview:self.mainaTableVie];
    
    
    
    
}






- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataMuarr.count;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {
    
    
    static NSString *cellID = @"cellID";
    HWyouxixiqiangpinglunTableViewCell  *cell  = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {

        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWyouxixiqiangpinglunTableViewCell" owner:nil options:nil].firstObject;
        
        
        
        

    }
    NSDictionary *dic  =  self.dataMuarr[indexPath.row];
    
    
    NSURL *url = [NSURL URLWithString:dic[@"face"]];
    
    [cell.icoimaview sd_setImageWithURL:url placeholderImage:nil];
    
    cell.mingchengLabel.text = [NSString stringWithFormat:@"%@",dic[@"user_name"]];
    
    
    cell.riqilabel.text = [NSString stringWithFormat:@"%@",dic[@"time"]];
    
    
    NSString *jiajing = [NSString stringWithFormat:@"%@",dic[@"jiajing"]];
    
    if ([jiajing intValue] == 1) {
        
        
        cell.leironglabel.text = [NSString stringWithFormat:@"                %@",dic[@"content"]];
       //  cell.leironglabel.text = [NSString stringWithFormat:@"            %@",dic[@"content"]];
        cell.youzhiicoimageView.hidden = NO;
        
        
    } else {
        
        
        
        cell.leironglabel.text = [NSString stringWithFormat:@"%@",dic[@"content"]];
        cell.youzhiicoimageView.hidden = YES;
        
    
        
    }
    
    

    

    cell.selectionStyle =  UITableViewCellSelectionStyleNone;

    return  cell;

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
     NSDictionary *dic  =  self.dataMuarr[indexPath.row];
    
    NSString *jiajing = [NSString stringWithFormat:@"%@",dic[@"jiajing"]];
           NSString   *contentStr = @"";
         if ([jiajing intValue] == 1) {
           
           
          contentStr = [NSString stringWithFormat:@"                %@",dic[@"content"]];
         
           
           
       } else {
       
           
                contentStr = [NSString stringWithFormat:@"%@",dic[@"content"]];
         
           
       }
           
           
           
     CGFloat  contentH = [self  jisuncalculateRowHeight:contentStr fontSize:12];
    
    
    
     return  contentH+56+5;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
   
    
}




//重新计算高度 类容
- (CGFloat)jisuncalculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize

{
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
    
    CGRect rect = [string boundingRectWithSize:CGSizeMake(kScreenW-40, MAXFLOAT)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    
    return rect.size.height;
    //demo123456
    
}




@end
